<!DOCTYPE html>


<html lang="zh_CN">
  

    <head>
      <meta charset="utf-8" />
        
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
      <title>SpringCloud Bus消息总线 |  MyBlog</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/favicon.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css"
      />
      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    <link rel="alternate" href="/atom.xml" title="MyBlog" type="application/atom+xml">
</head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="SpringCloud-SpringCloud Bus消息总线"
  class="article article-type-SpringCloud"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  SpringCloud Bus消息总线
</h1>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2022/03/12/SpringCloud%20Bus%E6%B6%88%E6%81%AF%E6%80%BB%E7%BA%BF/" class="article-date">
  <time datetime="2022-03-12T14:28:20.000Z" itemprop="datePublished">2022-03-12</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/SpringCloud/">SpringCloud</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.5k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">6 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="十四、SpringCloud-Bus消息总线"><a href="#十四、SpringCloud-Bus消息总线" class="headerlink" title="十四、SpringCloud Bus消息总线"></a>十四、SpringCloud Bus消息总线</h1><h2 id="14-1-概述"><a href="#14-1-概述" class="headerlink" title="14.1.概述"></a>14.1.概述</h2><h3 id="14-1-1-提供了分布式自动刷新配置功能"><a href="#14-1-1-提供了分布式自动刷新配置功能" class="headerlink" title="14.1.1.提供了分布式自动刷新配置功能"></a>14.1.1.提供了分布式自动刷新配置功能</h3><p>与config配置中心结合使用</p>
<h3 id="14-1-2-消息总线是什么"><a href="#14-1-2-消息总线是什么" class="headerlink" title="14.1.2.消息总线是什么"></a>14.1.2.消息总线是什么</h3><p><font color='blue'>Spring Cloud Bus 配合 Spring Cloud Config 使用可以实现配置的动态刷新。</font></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062130081.png" alt="image-20220306213040883"></p>
<p>Spring Cloud Bus是用来将分布式系统的节点与轻量级消息系统链接起来的框架，</p>
<p><font color='red'>它整合了Java的事件处理机制和消息中间件的功能。</font></p>
<p>Spring Clud Bus<strong>目前支持RabbitMQ和Kafka。</strong></p>
<h3 id="14-1-3-消息总线的用途"><a href="#14-1-3-消息总线的用途" class="headerlink" title="14.1.3.消息总线的用途"></a>14.1.3.消息总线的用途</h3><p>Spring Cloud Bus能管理和传播分布式系统间的消息，就像一个分布式执行器，可用于广播状态更改、事件推送等，也可以当作微服务间的通信通道。</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062133556.png" alt="image-20220306213337098"></p>
<h3 id="14-1-4-为什么被称为消息总线"><a href="#14-1-4-为什么被称为消息总线" class="headerlink" title="14.1.4.为什么被称为消息总线"></a>14.1.4.为什么被称为消息总线</h3><h4 id="1-什么是总线"><a href="#1-什么是总线" class="headerlink" title="1.什么是总线"></a>1.什么是总线</h4><p>在微服务架构的系统中，通常会<strong>使用轻量级的消息代理来构建一个共用的消息主题</strong>，并让系统中所有微服务实例都连接上来。由于该主题中产生的消息会被所有实例监听和消费，所以称它为消息总线。在总线上的各个实例，都可以方便地广播一些需要让其他连接在该主题上的实例都知道的消息。</p>
<h4 id="2-基本原理"><a href="#2-基本原理" class="headerlink" title="2.基本原理"></a>2.基本原理</h4><p>ConfigClient实例都监听MQ中同一个topic(默认是springCloudBus)。<strong>当一个服务刷新数据的时候，它会把这个信息放入到Topic中</strong>，这样其它监听同一Topic的服务就能得到通知，然后去更新自身的配置。</p>
<h2 id="14-2-RabbitMQ环境配置"><a href="#14-2-RabbitMQ环境配置" class="headerlink" title="14.2.RabbitMQ环境配置"></a>14.2.RabbitMQ环境配置</h2><h3 id="14-2-1-安装Erlang语言"><a href="#14-2-1-安装Erlang语言" class="headerlink" title="14.2.1.安装Erlang语言"></a>14.2.1.安装Erlang语言</h3><p>安装rabbitmq之前需要安装erlang语言的支持</p>
<p>安装Erlang，下载地址：<a target="_blank" rel="noopener" href="http://erlang.org/download/">http://erlang.org/download/</a></p>
<p>安装步骤</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062058336.png" alt="image-20220306205846586"></p>
<p>自定义安装位置</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062101450.png" alt="image-20220306210121568"></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062102361.png" alt="image-20220306210157192"></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062102599.png" alt="image-20220306210214248"></p>
<h3 id="14-2-2-安装RabbitMQ"><a href="#14-2-2-安装RabbitMQ" class="headerlink" title="14.2.2.安装RabbitMQ"></a>14.2.2.安装RabbitMQ</h3><p>下载地址：<a target="_blank" rel="noopener" href="https://www.rabbitmq.com/previous.html">https://www.rabbitmq.com/previous.html</a></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062103457.png" alt="image-20220306210330893"></p>
<p>自定义安装位置</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062107184.png" alt="image-20220306210535486"></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062107013.png" alt="image-20220306210600139"></p>
<h3 id="14-2-3-安装可视化插件"><a href="#14-2-3-安装可视化插件" class="headerlink" title="14.2.3.安装可视化插件"></a>14.2.3.安装可视化插件</h3><p>进入rabbitmq server目录下的sbin</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062140699.png" alt="image-20220306214052725"></p>
<p>在此处输入cmd，然后输入以下命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rabbitmq-plugins <span class="built_in">enable</span> rabbitmq_management</span><br></pre></td></tr></table></figure>

<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062122894.png" alt="image-20220306212154704"></p>
<p>完成之后，我们的可视化界面就添加成功了，只要启动rabbitmq，然后在浏览器输入<a href="http://127.0.0.1:15672就可以访问了">http://127.0.0.1:15672就可以访问了</a></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062124371.png" alt="image-20220306212407857"></p>
<h3 id="14-2-4-运行访问测试"><a href="#14-2-4-运行访问测试" class="headerlink" title="14.2.4.运行访问测试"></a>14.2.4.运行访问测试</h3><p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062143963.png" alt="image-20220306214350107"></p>
<p><a target="_blank" rel="noopener" href="http://localhost:15672/">http://localhost:15672</a></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062214478.png" alt="image-20220306221457744"></p>
<p>当我们使用默认的账号密码（guest）时，若出现权限问题<font color='red'><strong>我们需要注意的是需要先关闭防火墙才可访问</strong></font></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062217182.png" alt="image-20220306221742827"></p>
<p>正常情况下，我们登录进来后的页面如下：</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062220105.png" alt="image-20220306222035650"></p>
<h2 id="14-3-SpringCloud-Bus动态刷新全局广播"><a href="#14-3-SpringCloud-Bus动态刷新全局广播" class="headerlink" title="14.3.SpringCloud Bus动态刷新全局广播"></a>14.3.SpringCloud Bus动态刷新全局广播</h2><h3 id="14-3-1-准备好RabbitMQ环境"><a href="#14-3-1-准备好RabbitMQ环境" class="headerlink" title="14.3.1.准备好RabbitMQ环境"></a>14.3.1.准备好RabbitMQ环境</h3><h3 id="14-3-2-演示广播效果，将3355拷贝一份重命名为3366"><a href="#14-3-2-演示广播效果，将3355拷贝一份重命名为3366" class="headerlink" title="14.3.2.演示广播效果，将3355拷贝一份重命名为3366"></a>14.3.2.演示广播效果，将3355拷贝一份重命名为3366</h3><p>需要修改配置文件中的端口号，避免端口号冲突</p>
<p>修改业务类Controller</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RefreshScope</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ConfigClientController</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;server.port&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> String serverPort;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;config.info&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> String configInfo;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@GetMapping(&quot;/configInfo&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">configInfo</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;serverPort: &quot;</span>+serverPort+<span class="string">&quot;\t\n\n configInfo: &quot;</span>+configInfo;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="14-3-3-设计思想"><a href="#14-3-3-设计思想" class="headerlink" title="14.3.3.设计思想"></a>14.3.3.设计思想</h3><h4 id="1-利用消息总线触发一个客户端-bus-refresh-而刷新所有客户端的配置"><a href="#1-利用消息总线触发一个客户端-bus-refresh-而刷新所有客户端的配置" class="headerlink" title="1.利用消息总线触发一个客户端/bus/refresh,而刷新所有客户端的配置"></a>1.利用消息总线触发一个客户端/bus/refresh,而刷新所有客户端的配置</h4><p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062229822.png" alt="图一"></p>
<h4 id="2-利用消息总线触发一个服务端ConfigServer的-bus-refresh端点，而刷新所有客户端的配置"><a href="#2-利用消息总线触发一个服务端ConfigServer的-bus-refresh端点，而刷新所有客户端的配置" class="headerlink" title="2.利用消息总线触发一个服务端ConfigServer的/bus/refresh端点，而刷新所有客户端的配置"></a>2.利用消息总线触发一个服务端ConfigServer的/bus/refresh端点，而刷新所有客户端的配置</h4><p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062230298.png" alt="图二"></p>
<h4 id="3-图二的架构更加适合，图一不适合的原因"><a href="#3-图二的架构更加适合，图一不适合的原因" class="headerlink" title="3.图二的架构更加适合，图一不适合的原因"></a>3.图二的架构更加适合，图一不适合的原因</h4><ul>
<li>破坏职责单一性，因为微服务本身时业务模块，它本不应该承担配置刷新的职责。</li>
<li>破坏了微服务各节点的对等性</li>
<li>有一定的局限性。例如，微服务在迁移时，它的网络地址常常发生变化，此时想要做到自动刷新，那就会增加更多的修改</li>
</ul>
<h3 id="14-3-4-给cloud-config-center3344配置中心服务端添加消息总线支持"><a href="#14-3-4-给cloud-config-center3344配置中心服务端添加消息总线支持" class="headerlink" title="14.3.4.给cloud-config-center3344配置中心服务端添加消息总线支持"></a>14.3.4.给cloud-config-center3344配置中心服务端添加消息总线支持</h3><h4 id="1-修改pom文件"><a href="#1-修改pom文件" class="headerlink" title="1.修改pom文件"></a>1.修改pom文件</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--添加消息总线RabbitMQ支持--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-bus-amqp<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-actuator<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="2-修改yml"><a href="#2-修改yml" class="headerlink" title="2.修改yml"></a>2.修改yml</h4><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="comment">#rabbitmq相关配置</span></span><br><span class="line">  <span class="attr">rabbitmq:</span></span><br><span class="line">    <span class="attr">host:</span> <span class="string">localhost</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">5672</span></span><br><span class="line">    <span class="attr">username:</span> <span class="string">guest</span></span><br><span class="line">    <span class="attr">password:</span> <span class="string">guest</span></span><br><span class="line"></span><br><span class="line"><span class="comment">##rabbitmq相关配置,暴露bus刷新配置的端点</span></span><br><span class="line"><span class="attr">management:</span></span><br><span class="line">  <span class="attr">endpoints:</span> <span class="comment">#暴露bus刷新配置的端点</span></span><br><span class="line">    <span class="attr">web:</span></span><br><span class="line">      <span class="attr">exposure:</span></span><br><span class="line">        <span class="attr">include:</span> <span class="string">&quot;busfresh&quot;</span></span><br></pre></td></tr></table></figure>

<p><strong>官网原话翻译</strong>：</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062253856.png" alt="image-20220306225348621"></p>
<h3 id="14-3-5-给cloud-config-client3355客户端添加消息总线支持"><a href="#14-3-5-给cloud-config-client3355客户端添加消息总线支持" class="headerlink" title="14.3.5.给cloud-config-client3355客户端添加消息总线支持"></a>14.3.5.给cloud-config-client3355客户端添加消息总线支持</h3><h4 id="1-修改pom文件-1"><a href="#1-修改pom文件-1" class="headerlink" title="1.修改pom文件"></a>1.修改pom文件</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--添加消息总线RabbitMQ支持--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-bus-amqp<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-actuator<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="2-修改yml-1"><a href="#2-修改yml-1" class="headerlink" title="2.修改yml"></a>2.修改yml</h4><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="comment">#rabbitmq相关配置</span></span><br><span class="line">  <span class="attr">rabbitmq:</span></span><br><span class="line">    <span class="attr">host:</span> <span class="string">localhost</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">5672</span></span><br><span class="line">    <span class="attr">username:</span> <span class="string">guest</span></span><br><span class="line">    <span class="attr">password:</span> <span class="string">guest</span></span><br><span class="line"></span><br><span class="line"><span class="comment">##rabbitmq相关配置,暴露bus刷新配置的端点</span></span><br><span class="line"><span class="attr">management:</span></span><br><span class="line">  <span class="attr">endpoints:</span> <span class="comment">#暴露bus刷新配置的端点</span></span><br><span class="line">    <span class="attr">web:</span></span><br><span class="line">      <span class="attr">exposure:</span></span><br><span class="line">        <span class="attr">include:</span> <span class="string">&#x27;*&#x27;</span></span><br></pre></td></tr></table></figure>

<h3 id="14-3-6-给cloud-config-client3366客户端添加消息总线支持"><a href="#14-3-6-给cloud-config-client3366客户端添加消息总线支持" class="headerlink" title="14.3.6.给cloud-config-client3366客户端添加消息总线支持"></a>14.3.6.给cloud-config-client3366客户端添加消息总线支持</h3><h4 id="1-修改pom文件-2"><a href="#1-修改pom文件-2" class="headerlink" title="1.修改pom文件"></a>1.修改pom文件</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--添加消息总线RabbitMQ支持--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-bus-amqp<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-actuator<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="2-修改yml-2"><a href="#2-修改yml-2" class="headerlink" title="2.修改yml"></a>2.修改yml</h4><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="comment">#rabbitmq相关配置</span></span><br><span class="line">  <span class="attr">rabbitmq:</span></span><br><span class="line">    <span class="attr">host:</span> <span class="string">localhost</span></span><br><span class="line">    <span class="attr">port:</span> <span class="number">5672</span></span><br><span class="line">    <span class="attr">username:</span> <span class="string">guest</span></span><br><span class="line">    <span class="attr">password:</span> <span class="string">guest</span></span><br><span class="line"></span><br><span class="line"><span class="comment">##rabbitmq相关配置,暴露bus刷新配置的端点</span></span><br><span class="line"><span class="attr">management:</span></span><br><span class="line">  <span class="attr">endpoints:</span> <span class="comment">#暴露bus刷新配置的端点</span></span><br><span class="line">    <span class="attr">web:</span></span><br><span class="line">      <span class="attr">exposure:</span></span><br><span class="line">        <span class="attr">include:</span> <span class="string">&#x27;*&#x27;</span></span><br></pre></td></tr></table></figure>

<h3 id="14-3-7-测试"><a href="#14-3-7-测试" class="headerlink" title="14.3.7.测试"></a>14.3.7.测试</h3><p>将7001，3344，3355，3366一次启动，确保都能访问到gitee上的配置文件后再做下一步操作</p>
<p>修改gitee上的配置文件version，如何通过浏览器访问，我们会发现目前只有3344配置中心服务端可以直接访问到更新后的内容。</p>
<p>win + R 后输入cmd</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X POST <span class="string">&quot;http://localhost:3344/actuator/bus-refresh&quot;</span></span><br></pre></td></tr></table></figure>

<p>再次访问客户端，发现可以访问到更新后的内容了。</p>
<h3 id="14-3-8-实现原理"><a href="#14-3-8-实现原理" class="headerlink" title="14.3.8.实现原理"></a>14.3.8.实现原理</h3><p>配置中心服务端通过命令，将获取到的新的配置文件内容暴露到rabbitmq中，客户端通过订阅获取到最新的内容</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062328812.png" alt="image-20220306232800948"></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203062359850.png" alt="原理图"></p>
<h2 id="14-4-SpringCloud-Bus动态刷新定点通知"><a href="#14-4-SpringCloud-Bus动态刷新定点通知" class="headerlink" title="14.4.SpringCloud Bus动态刷新定点通知"></a>14.4.SpringCloud Bus动态刷新定点通知</h2><p>目的：只通知3355，不通知3366</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X POST <span class="string">&quot;http://localhost:3344/actuator/bus-refresh/config-client:3355&quot;</span></span><br></pre></td></tr></table></figure>

<h1 id=""><a href="#" class="headerlink" title=""></a></h1> 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2022/03/12/SpringCloud%20Bus%E6%B6%88%E6%81%AF%E6%80%BB%E7%BA%BF/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/SpringCloud/" rel="tag">SpringCloud</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2022/03/12/SpringCloud%20Alibaba%E5%85%A5%E9%97%A8%E7%AE%80%E4%BB%8B/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            SpringCloud Alibaba入门简介
          
        </div>
      </a>
    
    
      <a href="/2022/03/12/SpringCloud%20Sleuth%E5%88%86%E5%B8%83%E5%BC%8F%E8%AF%B7%E6%B1%82%E9%93%BE%E8%B7%AF%E8%B7%9F%E8%B8%AA/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">SpringCloud Sleuth分布式请求链路跟踪</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "",
    app_key: "",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
   
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2022
        <i class="ri-heart-fill heart_icon"></i> Yuan
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></span>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="MyBlog"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->
 
<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: ".tocbot",
    contentSelector: ".article-entry",
    headingSelector: "h1, h2, h3, h4, h5, h6",
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: "main",
    positionFixedSelector: ".tocbot",
    positionFixedClass: "is-position-fixed",
    fixedSidebarOffset: "auto",
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->
 <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script> 
<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->
 
<script src="/js/busuanzi-2.3.pure.min.js"></script>
 
<!-- ClickLove -->
 
<script src="/js/clickLove.js"></script>
 
<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->
 
<link rel="stylesheet" href="/css/clipboard.css">
 <script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>
 
<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    <div id="music">
    
    
    
    <iframe frameborder="no" border="1" marginwidth="0" marginheight="0" width="200" height="52"
        src="//music.163.com/outchain/player?type=2&id=22707008&auto=1&height=32"></iframe>
</div>

<style>
    #music {
        position: fixed;
        right: 15px;
        bottom: 0;
        z-index: 998;
    }
</style>
    
    

  </div>
</body>

</html>